package com.raincat.tools.multimediapickertools.utils;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import org.jetbrains.annotations.NotNull;

/**
 * <pre>
 *     author : RainCat
 *     e-mail : nining377@gmail.com
 *     time   : 2022/03/01
 *     desc   : 间隙
 *     version: 1.0
 * </pre>
 */

public class GridSpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int space;  //位移间距
    private int spanCount;  //一行item个数

    public GridSpaceItemDecoration(int space, int spanCount) {
        this.space = space;
        this.spanCount = spanCount;
    }

    @Override
    public void getItemOffsets(@NotNull Rect outRect, @NotNull View view, @NotNull RecyclerView parent, @NotNull RecyclerView.State state) {
        outRect.left = space / 2;
        outRect.right = space / 2;
        outRect.bottom = space;
        //顶部也有缝隙
        if (parent.getChildLayoutPosition(view) < spanCount) {
            outRect.top = space;
        }
    }
}
